﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using iShoppingBUS;
using iShoppingDTO;

namespace iShopping.Admin.UserControl
{
    public partial class ThemQuyen : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                FillPhanQuyen();
            }
        }
        private void FillPhanQuyen()
        {
            DataTable dt = PhanQuyenBUS.SelectAllQuyen();
            GridView1.DataSource = dt;
            GridView1.DataBind();
        }

        protected void GridView1_PageIndexChanging(object sender, GridViewPageEventArgs e)
        {
            GridView1.PageIndex = e.NewPageIndex;
            FillPhanQuyen();
        }

        protected void GridView1_RowCancelingEdit(object sender, GridViewCancelEditEventArgs e)
        {

        }

        protected void GridView1_RowDeleting(object sender, GridViewDeleteEventArgs e)
        {
            //  xóa quyền
            if (GridView1.DataKeys != null)
            {
                string maQuyen = GridView1.DataKeys[e.RowIndex].Value.ToString();
                bool result = PhanQuyenBUS.DeleteQuyenofMa(maQuyen);
                if (result)
                {
                    FillPhanQuyen();
                }
            }
        }

        protected void GridView1_RowEditing(object sender, GridViewEditEventArgs e)
        {

        }

        protected void GridView1_RowUpdated(object sender, GridViewUpdatedEventArgs e)
        {

        }

        protected void GridView1_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {

        }

        protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
        {

        }

        protected void btnThem_Click(object sender, EventArgs e)
        {
            string tenQuyen = txtTenQuyen.Text.Trim();
            string maQuyen = txtMaQuyen.Text.Trim();
            PhanQuyenDTO phanQuyenDto = new PhanQuyenDTO();
            if (!String.IsNullOrEmpty(tenQuyen) && !String.IsNullOrEmpty(maQuyen))
            {
                phanQuyenDto.MaPhanQuyen = maQuyen;
                phanQuyenDto.TenQuyen = tenQuyen;
                bool result = PhanQuyenBUS.InsertPhanQuyen(phanQuyenDto);
                if(result)
                {
                    FillPhanQuyen();
                }
           }
        }

        protected void GridView1_SelectedIndexChanged1(object sender, EventArgs e)
        {

        }
   
    }
}